﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
	SqlConnection conn = new SqlConnection();

	protected void Page_Load(object sender, EventArgs e)
	{

	}
	protected void btnConnect_Click(object sender, EventArgs e)
	{
		string strConnectionString = "server=127.0.0.1;uid=sa;pwd=liuxiaozeng;database=NorthwindCHS";
		conn.ConnectionString = strConnectionString;

		try
		{
			conn.Open();

//            string commandText = @"SELECT 类别ID,类别名称,说明
//									FROM 类别
//									WHERE 类别名称 LIKE '%" + txtKeyword.Text + "%'";
//            SqlCommand command = new SqlCommand(commandText, conn);


//            SqlDataReader dr = command.ExecuteReader();
//            while (dr.Read())
//            {
//                Response.Write(dr["类别ID"] + ", " + dr["类别名称"] + ", " + dr["说明"] + "<br>");
//            }

//            dr.Close();
//            conn.Close();

			DataSet ds = new DataSet();
			SqlDataAdapter da = new SqlDataAdapter(@"SELECT 类别ID,类别名称,说明 FROM 类别", conn);
			da.Fill(ds);

			GridView1.DataSource = ds;
			GridView1.DataBind();
		}
		catch (Exception ex)
		{

			Response.Write(ex.Message);
		}

	}
	protected void btnState_Click(object sender, EventArgs e)
	{


	}
	protected void btnClose_Click(object sender, EventArgs e)
	{
		conn.Close();

		if (conn.State == ConnectionState.Closed)
		{
			Response.Write("数据库连接现在处于关闭状态");
		}
	}
}
